package com.yingjie.yingjiekitchen.controller;

import com.yingjie.commonbase.commons.ReturnObject;
import com.yingjie.commonbase.model.Kitchen;
import com.yingjie.commonsecurity.AuthUserContext;
import com.yingjie.yingjiekitchen.model.FoodType;
import com.yingjie.yingjiekitchen.service.FoodTypeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;

@RestController
@RequestMapping("/foodType")
public class FoodTypeController {


    @Resource
    private FoodTypeService foodTypeService;
    @PostMapping("/create")
    public ReturnObject create(@RequestBody FoodType foodType){
        Integer userId = AuthUserContext.get().getUserId();
        foodType.setUserId(userId);
        foodType.setFoodTypeName(foodType.getFoodTypeName());
        foodType.setCreatedAt(new Date());
        int result = foodTypeService.create(foodType);
        if(result==0){
            return ReturnObject.ERROR("创建失败");
        }
        return ReturnObject.SUCCESS(foodType.getFoodTypeId());
    }

    @PostMapping("/getFoodTypeList")
    public ReturnObject getFoodTypeList(@RequestBody Kitchen kitchen){
        ArrayList<FoodType> foodTypes = foodTypeService.getFoodTypeList(kitchen.getKitchenId());
        return ReturnObject.SUCCESS(foodTypes);
    }

}
